package com.jl.js.filepath;

public class FilePathUtil {
	public static IJsFilePath getJSFilePath(String name) {
		if (name.startsWith("#/")) {
			return new ProjectFilePath(name);
		} else if(name.startsWith("$/")){
			return new WorkspacePath(name);
		}else {
			return new NormalFilePath(name);
		}
	}
	
	/**
	 * replace all "\" to "/"
	 * @param path
	 * @return
	 */
	public static String replaceAllAndRemoveEndSegment(String path){
		StringBuilder sb = new StringBuilder();
		for(char ch : path.toCharArray()){
			if(ch == '/'){
				ch = '\\';
			}
			sb.append(ch);
		}
		if(sb.charAt(sb.length() - 1) == '\\'){
			sb.delete(sb.length() -1, sb.length());
		}
		return sb.toString();
	}
}
